package org.nidy.programexercise.MethodCitation;

import org.nidy.programexercise.Exception.CustomException;

public class Student {
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    private String name;
    private int age;

    public Student(String s) {
        String[] split = s.split(",");
        this.name= split[0];
        this.age = Integer.parseInt(split[1]);

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length()<3 ||name.length()>10){
            throw new CustomException("名字长度在3-10之间");
        }
        this.name = name;
    }

    public int getAge() {

        return age;
    }

    public void setAge(int age) {
        if (age<0 || age>100){
            throw new CustomException("年龄在0-100之间");
        }
        this.age = age;
    }

    public void print() {
        System.out.println("name = " + name + ", age = " + age);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
